using System.ComponentModel.DataAnnotations;

namespace CoreManager.Models.DTOs
{
    /// <summary>
    /// 角色响应DTO
    /// </summary>
    public class RoleDto
    {
        /// <summary>
        /// 角色ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 角色名称
        /// </summary>
        public string RoleName { get; set; } = string.Empty;

        /// <summary>
        /// 角色编码
        /// </summary>
        public string RoleCode { get; set; } = string.Empty;

        /// <summary>
        /// 排序
        /// </summary>
        public int Sort { get; set; }

        /// <summary>
        /// 状态 0:禁用 1:启用
        /// </summary>
        public int Status { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remark { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime? UpdateTime { get; set; }

        /// <summary>
        /// 角色关联的菜单权限ID列表
        /// </summary>
        public List<int> MenuIds { get; set; } = new List<int>();

        /// <summary>
        /// 角色关联的菜单权限列表
        /// </summary>
        public List<MenuDto> Menus { get; set; } = new List<MenuDto>();
    }

    /// <summary>
    /// 角色创建请求DTO
    /// </summary>
    public class CreateRoleDto
    {
        /// <summary>
        /// 角色名称
        /// </summary>
        [Required(ErrorMessage = "角色名称不能为空")]
        [MaxLength(50, ErrorMessage = "角色名称长度不能超过50个字符")]
        public string RoleName { get; set; } = string.Empty;

        /// <summary>
        /// 角色编码
        /// </summary>
        [Required(ErrorMessage = "角色编码不能为空")]
        [MaxLength(50, ErrorMessage = "角色编码长度不能超过50个字符")]
        public string RoleCode { get; set; } = string.Empty;

        /// <summary>
        /// 排序
        /// </summary>
        public int Sort { get; set; } = 0;

        /// <summary>
        /// 状态 0:禁用 1:启用
        /// </summary>
        [Range(0, 1, ErrorMessage = "状态值必须为0或1")]
        public int Status { get; set; } = 1;

        /// <summary>
        /// 备注
        /// </summary>
        [MaxLength(500, ErrorMessage = "备注长度不能超过500个字符")]
        public string? Remark { get; set; }

        /// <summary>
        /// 菜单权限ID列表
        /// </summary>
        public List<int> MenuIds { get; set; } = new List<int>();
    }

    /// <summary>
    /// 角色更新请求DTO
    /// </summary>
    public class UpdateRoleDto
    {
        /// <summary>
        /// 角色名称
        /// </summary>
        [Required(ErrorMessage = "角色名称不能为空")]
        [MaxLength(50, ErrorMessage = "角色名称长度不能超过50个字符")]
        public string RoleName { get; set; } = string.Empty;

        /// <summary>
        /// 角色编码
        /// </summary>
        [Required(ErrorMessage = "角色编码不能为空")]
        [MaxLength(50, ErrorMessage = "角色编码长度不能超过50个字符")]
        public string RoleCode { get; set; } = string.Empty;

        /// <summary>
        /// 排序
        /// </summary>
        public int Sort { get; set; } = 0;

        /// <summary>
        /// 状态 0:禁用 1:启用
        /// </summary>
        [Range(0, 1, ErrorMessage = "状态值必须为0或1")]
        public int Status { get; set; } = 1;

        /// <summary>
        /// 备注
        /// </summary>
        [MaxLength(500, ErrorMessage = "备注长度不能超过500个字符")]
        public string? Remark { get; set; }

        /// <summary>
        /// 菜单权限ID列表
        /// </summary>
        public List<int> MenuIds { get; set; } = new List<int>();
    }

    /// <summary>
    /// 角色查询请求DTO
    /// </summary>
    public class RoleQueryDto
    {
        /// <summary>
        /// 角色名称（模糊查询）
        /// </summary>
        public string? RoleName { get; set; }

        /// <summary>
        /// 角色编码（模糊查询）
        /// </summary>
        public string? RoleCode { get; set; }

        /// <summary>
        /// 状态 0:禁用 1:启用
        /// </summary>
        public int? Status { get; set; }
    }

    /// <summary>
    /// 角色权限分配请求DTO
    /// </summary>
    public class AssignRolePermissionsDto
    {
        /// <summary>
        /// 角色ID
        /// </summary>
        [Required(ErrorMessage = "角色ID不能为空")]
        public int RoleId { get; set; }

        /// <summary>
        /// 菜单权限ID列表
        /// </summary>
        public List<int> MenuIds { get; set; } = new List<int>();
    }
}
